﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.IO;

namespace MaterialEditor
{
    public static class EffectManager
    {
        public static Effect BasicShader;

        public static Effect InvertShader;

        public static Effect AddShader;

        public static Effect MultShader;

        public static Effect Ads;

        private static string Root
        {
            get { return Environment.CurrentDirectory + "\\Content\\"; }
        }

        private static Effect compileEffect(string filename)
        {
            ContentBuilder b = Form1.instance.contentBuilder;
            b.Clear();

            string name = Path.GetFileName(filename).Split(new char[] { '.' })[0];

            b.Add(filename, name, "EffectImporter", "EffectProcessor");
            string err_msg = b.Build();
            if (string.IsNullOrEmpty(err_msg))
            {
                Effect outval = Form1.instance.content.Load<Effect>(name);
                return outval;
            }
            else
                System.Windows.Forms.MessageBox.Show(err_msg);
            return null;
        }

        public static void Inilitize()
        {
            BasicShader = compileEffect(Root + "BasicShader.fx");
            InvertShader = compileEffect(Root + "Texture\\Invert.fx");
            AddShader = compileEffect(Root + "Texture\\Add.fx");
            MultShader = compileEffect(Root + "Texture\\Mult.fx");
            Ads = compileEffect(Root + "AdsLight.fx");
        }
    }
}